Vue.component('comlist', {
  template: '<div class="grid-content">' +
    '<el-table :data="comData"  border style="width: 100%;" class="w-tablesub">'+
	    '<el-table-column prop="recvdeptname" label="接收部门" width="120">'+
	    '</el-table-column>'+
	    '<el-table-column prop="recvopername" label="接收人">'+
	    '</el-table-column>'+
	    '<el-table-column  label="回复内容" width="300" class="w-textsub">'+
	         '<template slot-scope="scope">'+
	             '<el-popover trigger="hover" placement="top-start">'+
	                 '<p class="w-tablepop">{{ scope.row.comm }}</p>'+
	                 '<div slot="reference" >'+
	                    '{{ scope.row.comm }}'+
	                 '</div>'+		                           
	             '</el-popover>'+
	         '</template>'+
		'</el-table-column>'+
		'<el-table-column prop="recv_date" label="阅读时间">'+
	    '</el-table-column>'+                               
	    '<el-table-column prop="read_status_name" label="阅读状态">'+
	    '</el-table-column>'+
	    '<el-table-column label="操作" v-if="operable">'+
	    '<template slot-scope="scope">'+
        	'<i class="el-icon-delete" v-if="delable" title="删除" style="cursor:pointer;" @click="del(scope.row)"></i>'+
        '</template>'+
	    '</el-table-column>'+
    '</el-table>'+
    '<div class="block mt10">'+
	    '<el-pagination @size-change="handleSizeChange"'+
	        '@current-change="handleCurrentChange"'+
	        ':current-page="currentPageNbr" :page-sizes="pageSizes"'+
	        ':page-size="pageSize" class="w-tc"'+
	        'layout="total, sizes, prev, pager, next, jumper"'+
	        ':total="totalRecords"> </el-pagination>'+
     '</div>'+
   '</div>',
//    '<div class="mt10"></div>'+
//    '<el-row class="text-center"> '+
//    '    <el-button type="primary" v-if="!scoreReadOnly" @click="onInnerTableSave" :disabled="saving">保存</el-button>'+
//    '    <el-button type="primary" v-if="!scoreReadOnly" @click="onInnerTableSaveAndCommit" :disabled="commiting">保存并提交</el-button>'+
//    '    <el-button  type="primary" @click="onInnerTableCancel">关闭</el-button> '+
//    '</el-row> </div>',
  props: {
	args: {
		type: Object
    },
   // delable: Boolean
    delable: {
    	type: Boolean,
    	default: false
    	},
  },  
  data: function(){
    return {
    	msgId:'',
    	comData:[],
    	operType:'sendUser',
    	currentPageNbr: config.currentPageNbr,
        pageSizes: config.pageSizes,
        pageSize: config.defaultpageSize,
        totalRecords: 0,      
        operable: false
    }
  },
  beforeDestory: function(){
	   console.log("destory");
  },
  mounted: function () {
	 this.initData();
  },
  methods: {
    initData:function(){
    	
    }, 
    refresh:function(){
    	this.currentPageNbr = config.currentPageNbr;
    	this.pageSize = config.defaultpageSize;
    	this.onSearch();
    },
    onSearch:function(){
    	if(this.delable) 
    		this.operable = true;
    	this.msgId = this.args.msgId;
    	var that =this;
    	var jsonStr = {
    	  "msgId" : this.msgId,
    	  "operType": this.operType,
    	};
    	var reqData ={
    	  "jsonStr": JSON.stringify(jsonStr),
    	  "currentPageNbr" : this.currentPageNbr,
    	  "pageSize": this.pageSize
    	};
    	tools.ajaxRequestAsyncEx("pub/msg/msgDetailList", reqData, function(data){
    	   if (data.respCode == "0") {
    	       that.comData = data.list;
    	       that.totalRecords = data.page.totalRecords;       
    	   } else {
    	       that.msgData = [];
    	       that.totalRecords =0;
    	       that.currentPageNbr=1;
    	       that.showError(data.respDesc);      
    	   }
//    	   setTimeout(function(){
//    	       if(window.parent != window) {
//    	        		  window.parent.util.setFrameHeight(window, $("#app").height());
//    	        }   		  
//    	    	}, 100);
    	});
    },
    del:function(row){
    	var that =this;
    	var jsonStr = {
    		"detail_id": row.detail_id
    	};
    	var reqData = {	
    		"jsonStr":JSON.stringify(jsonStr)
    	};
    	this.$confirm('确定删除接收人-'+row.recv_oper_code_name+' 消息?', '提示', {
	            confirmButtonText: '确定',
	            cancelButtonText: '取消',
	            type: 'warning'
    	}).then(() => {
    		tools.ajaxRequestAsyncEx("pub/msg/msgDetailDel", reqData, function(data){
        		if (data.respCode == "0") {
        			that.$message({
    		            showClose: true,
    		            type: 'success',
    		            message: "删除成功"
    		        });  
        			that.refresh();
         	   } else {
         	       that.showError(data.respDesc);      
         	   }
        	});
	    }).catch(() => {     
	        	
	    });
    	
    },
    handleSizeChange:function(pageSize){
        this.pageSize = pageSize;
    },

    handleCurrentChange:function(currentPageNbr){
      this.currentPageNbr = currentPageNbr;
    },
    
    showError: function(info){
        var i = (info==undefined?"加载数据错误":info);
        this.$alert(i, '系统错误', {
             confirmButtonText: '确定'
        }); 
    },
    
  },
  
  watch:{
      currentPageNbr : function() {
          this.onSearch();
      },
        
      pageSize : function() {
    	  if(this.currentPageNbr=="1"){
    		  this.onSearch();
    	  }else{
    		  this.currentPageNbr=="1";
    	  }          
      },
  }
  
}) 
